﻿
Imports System.IO

Public Class Form1
    Public pas As String
    Public file As String
    Public bdir As String
    Public bfdir As String
    Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
        TextBox1.Text = Settings.Instance.mcid
        TextBox2.Text = Settings.Instance.mcpas
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Settings.LoadFromXmlFile()
        TextBox1.Text = Settings.Instance.mcid
        TextBox2.Text = Settings.Instance.mcpas
        TextBox3.Text = Settings.Instance.java
        TextBox4.Text = Settings.Instance.xms
        TextBox5.Text = Settings.Instance.xmx
        If System.IO.File.Exists(Application.StartupPath & "\target") Then
        Else
            Dim di As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Application.StartupPath & "\target")
            di.Create()
        End If
        If System.IO.Directory.Exists(Application.StartupPath & "\target") Then
            Dim directoryInfo As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\target")
            Dim directories As DirectoryInfo() = directoryInfo.GetDirectories()
            For i As Integer = 0 To directories.Length - 1
                If 0 <= directories(i).Name.IndexOf("mc_") Then
                    Dim fdn As String = directories(i).Name.Replace("mc_", "")
                    ComboBox1.Items.Add(fdn)
                    ListBox1.Items.Add(fdn)
                ElseIf 0 <= directories(i).Name.IndexOf("ftb_") Then
                    ComboBox1.Items.Add(directories(i))
                    ListBox1.Items.Add(directories(i))
                End If
            Next
        End If

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ComboBox1.Text = "" Then
        Else
            If CheckBox1.Checked = True Then
                Settings.Instance.mcid = TextBox1.Text
                Settings.Instance.mcpas = TextBox2.Text
                Settings.SaveToXmlFile()
            End If
            pas = ComboBox1.Text
            Module1.createbat()
            Shell(Application.StartupPath & "\boot.bat")
            ToolStripStatusLabel1.Text = ("状態: run " & pas)
        End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Form2.Show()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Settings.Instance.java = TextBox3.Text
        Settings.Instance.xms = TextBox4.Text
        Settings.Instance.xmx = TextBox5.Text
        Settings.SaveToXmlFile()
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        WebBrowser1.Navigate("http://mcupdate.tumblr.com/")
    End Sub

    Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
        ToolStripStatusLabel1.Text = ("状態:")
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If System.IO.Directory.Exists(Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\.minecraft\saves") Then
            Dim directoryInfo As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\.minecraft\saves")
            Dim directories As DirectoryInfo() = directoryInfo.GetDirectories()
            For i As Integer = 0 To directories.Length - 1
                ListBox2.Items.Add(directories(i).Name)
            Next
        End If
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If RadioButton1.Checked = True Then
            Dim addc As String = ""
            If TextBox6.Text = "" Then
            Else
                addc = TextBox6.Text
            End If
            file = "sv_" & Now.Year & "_" & Now.Month & "_" & Now.Day & "_" & Now.Hour & "_" & Now.Minute & "_" & ListBox2.SelectedItem & "_" & addc & ".zip"
            bdir = Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\.minecraft\saves\" & ListBox2.SelectedItem
            bfdir = Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\backup"
            Dim t As New System.Threading.Thread( _
            New System.Threading.ThreadStart( _
            AddressOf Module1.backup))
            t.Start()
        ElseIf RadioButton2.Checked = True Then
            Dim addc As String = ""
            If TextBox6.Text = "" Then
            Else
                addc = TextBox6.Text & "_"
            End If
            If ListBox2.SelectedItem.IndexOf("ftb_") Then

            End If
            file = "mc_" & Now.Year & "_" & Now.Month & "_" & Now.Day & "_" & Now.Hour & "_" & Now.Minute & "_" & ListBox2.SelectedItem & "_" & addc & ".zip"
            bdir = Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\.minecraft\"
            bfdir = Application.StartupPath & "\target\mc_" & ListBox1.SelectedItem & "\backup"
            Dim t As New System.Threading.Thread( _
            New System.Threading.ThreadStart( _
            AddressOf Module1.backup))
            t.Start()
        Else
            MsgBox("必ずどちらか選択してください。")
        End If
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        Dim target As String = Application.StartupPath & "\target\"
        System.IO.Directory.CreateDirectory(target & TextBox7.Text)
        System.IO.Directory.CreateDirectory(target & TextBox7.Text & "\backup")
    End Sub

    Private Sub ToolStripSplitButton1_ButtonClick(sender As Object, e As EventArgs)
        Form3.Show()
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            TextBox3.Text = OpenFileDialog1.FileName
        End If
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Form4.Show()
        Form4.ComboBox1.SelectedItem = ComboBox1.SelectedItem
        Form4.TextBox1.Text = TextBox1.Text
        Form4.TextBox2.Text = TextBox2.Text
        Me.WindowState = FormWindowState.Minimized
    End Sub
End Class